﻿using MaterialDesignThemes.Wpf;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace project.B12.Views.Dialog
{
    /// <summary>
    /// MessageDialogView.xaml 的交互逻辑
    /// </summary>
    public partial class MessageDialogView : UserControl
    {
        public MessageDialogView()
        {
            InitializeComponent();
        }
        public static async Task<bool> ComfirmMessage(string title, string content, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return false;
            var messageDialogView = new MessageDialogView
            {
                MessageTitle = { Text = title },
                MessageContent = { Text = content },
                DialogHostName = dialogHostName,
            };
            bool? dialogResult = (bool?)await DialogHost.Show(messageDialogView, dialogHostName);
            if (dialogResult == true)
                return true;
            else
                return false;
        }

        public string DialogHostName { get; internal set; }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            messageDialogView.Visibility = Visibility.Collapsed;//因UI界面关闭时短暂卡顿，点击关闭按钮后先折叠后关闭优化体验
            if (DialogHost.IsDialogOpen(DialogHostName))
                DialogHost.Close(DialogHostName, true);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            messageDialogView.Visibility = Visibility.Collapsed;//因UI界面关闭时短暂卡顿，点击关闭按钮后先折叠后关闭优化体验
            if (DialogHost.IsDialogOpen(DialogHostName))
                DialogHost.Close(DialogHostName, false);
        }
    }
}
